package com.example.backend.service.impl;

import com.example.backend.entity.StockRecord;
import com.example.backend.mapper.StockRecordMapper;
import com.example.backend.service.StockRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockRecordServiceImpl implements StockRecordService {
    @Autowired
    private StockRecordMapper stockRecordMapper;

    @Override
    public int addStockRecord(StockRecord stockRecord) {
        return stockRecordMapper.insert(stockRecord);
    }

    @Override
    public StockRecord getStockRecordById(Long id) {
        return stockRecordMapper.selectById(id);
    }

    @Override
    public List<StockRecord> getAllStockRecords() {
        return stockRecordMapper.selectAll();
    }

    @Override
    public int updateStockRecord(StockRecord stockRecord) {
        return stockRecordMapper.update(stockRecord);
    }

    @Override
    public int deleteStockRecord(Long id) {
        return stockRecordMapper.deleteById(id);
    }

    @Override
    public List<StockRecord> getStockRecordsByInId(Long inId) {
        return stockRecordMapper.selectByInId(inId);
    }

    @Override
    public List<StockRecord> getAvailableStockRecordsByCompanyAndPort(Long companyId, Long portId) {
        return stockRecordMapper.selectAvailableByCompanyAndPort(companyId, portId);
    }

    @Override
    public List<StockRecord> getStockRecordsByWarehouseId(Long warehouseId) {
        return stockRecordMapper.selectByWarehouseId(warehouseId);
    }

    @Override
    public List<StockRecord> getStockRecordsByCompanyId(Long companyId) {
        return stockRecordMapper.selectByCompanyId(companyId);
    }

    @Override
    public int updateRemainingWeight(Long id, java.math.BigDecimal newRemainingWeight) {
        return stockRecordMapper.updateRemainingWeight(id, newRemainingWeight);
    }

    @Override
    public java.math.BigDecimal getRemainingWeightByInId(Long inId) {
        return stockRecordMapper.selectRemainingWeightByInId(inId);
    }
} 